package com.dragon.mmochat.util;

import java.util.ArrayList;
import java.util.List;

import com.skymobi.buffer.SkymobiBuffer;
import com.skymobi.message.widget.TLVStructure;

//服务控件按键事件
public class TlvKeyEvent {	

	private int keyValue;
	private List<TLVStructure> keyEvent = null;

	public TlvKeyEvent() {

	}

	public TlvKeyEvent(int key) {
		keyValue = key;
	}

	public int getKeyValue() {
		return keyValue;
	}

	public void setKeyValue(int keyValue) {
		this.keyValue = keyValue;
	}

	public List<TLVStructure> getKeyEvent() {
		return keyEvent;
	}

	public void setKeyEvent(List<TLVStructure> eventTLVs) {
		this.keyEvent = eventTLVs;
	}

	public void addKeyEvent(TLVStructure tlv) {
		if (keyEvent == null) {
			synchronized (this) {
				if (keyEvent == null)
					keyEvent = new ArrayList<TLVStructure>();
			}
		}
		keyEvent.add(tlv);
	}

	/**
	 * uint16 keyValue; uint16 len; char *data;
	 * 
	 * @param out
	 */
	public void encode(SkymobiBuffer out) {
		out.putUnsignedShort(keyValue);
		out.putUnsignedShort(0);
		int start = out.position();
		for (TLVStructure structure : keyEvent)
			structure.encode(out);
		out.putUnsignedShort(start - 2, out.position() - start);
	}

}
